package com.jsp.servlet; /**
 * @author wzm
 * @create 2023-06-27 11:26
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/getAll")
public class GetAllStuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //准备10个学生数据  模拟查询数据库得到
        List<Student> list = new ArrayList<>();
        for (int i = 0; i < 10; i++){
            list.add(new Student(i+1,"student"+i));
        }

        //将10个学生存储到域对象中
        request.setAttribute("list", list);

        //转发到页面
        request.getRequestDispatcher("/student_list.jsp").forward(request,response);


    }
}
